<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '600px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title:{
          show:true,
          text:"辽宁省各市关键站退服数量"
        },
        tooltip:{
          formatter: "{b}关键站退服数量为：{c}"
        },
        legend: {
          top: 'bottom'
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [50, 200],
            center: ['50%', '50%'],
            itemStyle: {
              borderRadius: 8
            },
            data: [
              {value:1,name:'沈阳市'},
              {value:2,name:'大连市'},
              {value:3,name:'鞍山市'},
              {value:1,name:'抚顺市'},
              {value:4,name:'本溪市'},
              {value:7,name:'丹东市'},
              {value:2,name:'锦州市'},
              {value:1,name:'营口市'},
              {value:2,name:'阜新市'},
              {value:2,name:'辽阳市'},
              {value:5,name:'铁岭市'},
              {value:1,name:'朝阳市'},
              {value:1,name:'盘锦市'},
              {value:2,name:'葫芦岛市'}
            ]
          }
        ]
      })
    }
  }
}
</script>
